package tests;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;

import net.sourceforge.jeval.EvaluationException;
import exception.ExtraCharactersException;
import exception.IllegalCharacterSequenceException;
import exception.LessCharactersExeption;
import exception.NoRuleException;
import exception.UninitializedVariableException;

import model.ProgramGraph;
import model.TransitionSystem;
import utilities.GraphCreator;
import utilities.ParallellComposition;
import utilities.VSupervisorCreator;
import utilities.XMLWriter;

/** Class for parallel composition test of the printer supervisor
 * @author DarkoLaptop2
 *
 */
public class ParallellCompositionTester {

	/** Main method
	 * @param args
	 * @throws IOException
	 * @throws EvaluationException
	 * @throws UninitializedVariableException
	 * @throws IllegalCharacterSequenceException
	 * @throws LessCharactersExeption
	 * @throws ExtraCharactersException
	 * @throws NoRuleException
	 * @throws ParserConfigurationException
	 * @throws TransformerException
	 */
	public static void main(String[] args) throws IOException, EvaluationException, UninitializedVariableException, IllegalCharacterSequenceException, LessCharactersExeption, ExtraCharactersException, NoRuleException, ParserConfigurationException, TransformerException{
//		System.out.println(ParallellComposition.getNewLabel("20100", 0));
		TransitionSystem graph=GraphCreator.generateGraphWithoutVariables("graphs/CurentPowerMode.jff");
		TransitionSystem graph2=GraphCreator.generateGraphWithoutVariables("graphs/MaintenanceOperation.jff");
		TransitionSystem graph3=GraphCreator.generateGraphWithoutVariables("graphs/PageCounter.jff");
		TransitionSystem graph4=GraphCreator.generateGraphWithoutVariables("graphs/TargetPowerMode.jff");
		TransitionSystem graph5=GraphCreator.generateGraphWithoutVariables("graphs/MaintenanceScheduling.jff");
		System.out.println(graph2.toStringTransitionPrint());
		TransitionSystem[] graphs={graph,graph2,graph3,graph4,graph5};
		ProgramGraph parallell=ParallellComposition.parallellComposition(graphs);
		parallell.setRestrictionFilePath("graphs/restrictions_printing.txt");
		TransitionSystem supervisor=VSupervisorCreator.createSupervisor(parallell);
//		System.out.println(parallell.toStringTransitionPrint());
		FileWriter fw=new FileWriter("graphs/parallellCompositionResults.txt");
		BufferedWriter bw=new BufferedWriter(fw);
		bw.write(parallell.toStringTransitionPrint());
		bw.close();
		FileWriter fw2=new FileWriter("graphs/supervisor.txt");
		BufferedWriter bw2=new BufferedWriter(fw2);
		bw2.write(supervisor.toStringTransitionPrint());
		bw2.close();
		XMLWriter.writeXMLDocumentForSupervisor(supervisor, "graphs/supervisor.jff");
	}

}
